﻿Imports DTO
Imports BUS
Public Class ucNhanVien

    Dim nhanvien As New NhanVienDTO

    Private Sub barbtnThemHH_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnThemNV.ItemClick
        Dim frm As New frmThemNhanVien
        frm.ShowDialog()
    End Sub

    Private Sub LayDanhSachNhanVien()
        GCKhuVuc.DataSource = NhanVienBUS.LayDanhSachNhanVien()
    End Sub

    Private Sub ucNhanVien_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        barbtnXoaNV.Enabled = False
        barbtnSuaChuaNV.Enabled = False
        barbtnXuatNV.Enabled = False
        LayDanhSachNhanVien()
    End Sub

    Private Sub barbtnNapLaiNV_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnNapLaiNV.ItemClick
        LayDanhSachNhanVien()
    End Sub

    Private Sub barbtnSuaChuaNV_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnSuaChuaNV.ItemClick
        Dim frm As New frmThemNhanVien
        frm.kt = 1
        frm.maNV = nhanvien.MaNhanVien
        frm.tenNV = nhanvien.TenNhanVien
        frm.diaChi = nhanvien.DiaChi
        frm.dienThoai = nhanvien.DienThoai
        frm.diDong = nhanvien.DiDong
        frm.email = nhanvien.Email
        frm.ghiChu = nhanvien.GhiChu
        frm.maTT = nhanvien.MaTrangThai
        frm.maBoPhan = nhanvien.MaBoPhan
        frm.Text = "Sữa chửa nhân viên"
        frm.ShowDialog()
    End Sub

    Private Sub GridView1_RowClick(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowClickEventArgs) Handles GridView1.RowClick
        If e.RowHandle >= 0 Then
            barbtnXoaNV.Enabled = True
            barbtnSuaChuaNV.Enabled = True
            nhanvien.MaNhanVien = GridView1.GetRowCellValue(e.RowHandle, GCMaNV).ToString()
            nhanvien.TenNhanVien = GridView1.GetRowCellValue(e.RowHandle, GCTenNV).ToString()
            nhanvien.DiaChi = GridView1.GetRowCellValue(e.RowHandle, GCDiaChiNV).ToString()
            nhanvien.DienThoai = GridView1.GetRowCellValue(e.RowHandle, GCDienThoaiNV).ToString()
            nhanvien.DiDong = GridView1.GetRowCellValue(e.RowHandle, GCDiDongNV).ToString()
            nhanvien.GhiChu = GridView1.GetRowCellValue(e.RowHandle, GCGhiChuNV).ToString()
            nhanvien.Email = GridView1.GetRowCellValue(e.RowHandle, GCEmailNV).ToString()
            nhanvien.MaTrangThai = Convert.ToInt32(GridView1.GetRowCellValue(e.RowHandle, GCConQuanLyHH))
        End If
    End Sub

    Private Sub barbtnXoaNV_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles barbtnXoaNV.ItemClick
        Try
            If NhanVienBUS.XoaNhanVien(nhanvien) <> 0 Then
                DevExpress.XtraEditors.XtraMessageBox.Show("Xóa thành công nhân viên", "Thông Tin", MessageBoxButtons.OK, MessageBoxIcon.Information)
                LayDanhSachNhanVien()
            End If
        Catch ex As Exception
            DevExpress.XtraEditors.XtraMessageBox.Show("Nhân viên đã được sử dụng không thể xóa", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error)
            NhanVienBUS.DongKetNoi.Close()
        End Try
    End Sub

    Private Sub GridView1_CustomDrawRowIndicator(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles GridView1.CustomDrawRowIndicator
        If e.RowHandle >= 0 Then
            If e.Info.IsRowIndicator Then
                e.Info.DisplayText = (e.RowHandle + 1).ToString()
            End If
        End If
    End Sub
End Class
